package com.cookman.utils;

import com.cookman.actions.*;
import com.cookman.actions.automatic.CheckCardLimitAction;
import com.cookman.actions.events.BuildLabEventAction;
import com.cookman.actions.events.MoveToAnyCityEventAction;
import com.cookman.actions.events.RemoveDiseaseCardEventAction;
import com.cookman.actions.events.SkipInfectionEventAction;
import com.cookman.cards.CityCard;
import com.cookman.interfaces.Card;
import com.cookman.world.entities.*;

import java.util.List;

/**
 * Created by Cookman on 19.09.14.
 */
public class UiUtils {

    public static String actionLabelFunction(Action action) {
        if (action instanceof MovePlayerByCarAction) {
            return "By car";
        } else if (action instanceof MovePlayerByLabAction) {
            return "By lab";
        } else if (action instanceof MovePlayerCharterFlightAction) {
            return "By charter flight";
        } else if (action instanceof MovePlayerDirectFlightAction) {
            return "By direct flight";
        } else if (action instanceof BuildLabAsEngineerAction) {
            return "Build lab as Engineer";
        } else if (action instanceof BuildLabAction) {
            return "Build lab";
        } else if (action instanceof CureInfectionAction) {
            return "Cure infection";
        } else if (action instanceof InventCureAction) {
            return "Invent cure";
        } else if (action instanceof GiveCardToPlayerAction) {
            return "Give card of current city";
        } else if (action instanceof TakeCardFromPlayerAction) {
            return "Take card of current city from player";
        } else if (action instanceof GiveCardToPlayerByResearcherAction) {
            return "Give card as researcher";
        } else if (action instanceof MovePlayerByDispatcherAction) {
            return "Move player as dispatcher";
        } else if (action instanceof MovePlayerByDispatcherWithCardAction) {
            return "Move player as dispatcher with card";
        } else if (action instanceof TakeCardFromResearcherPlayerAction) {
            return "Take card from researcher";
        } else if (action instanceof MovePlayerAsEngineerAction) {
            return "Move as engineer";
        } else if (action instanceof SkipMoveAction) {
            return "Skip move";
        } else if (action instanceof BuildLabEventAction) {
            return "Build lab event card";
        } else if (action instanceof MoveToAnyCityEventAction) {
            return "Move to any city event card";
        } else if (action instanceof RemoveDiseaseCardEventAction) {
            return "Remove disease card  event card";
        } else if (action instanceof SkipInfectionEventAction) {
            return "Skip infection event card";
        } else if (action instanceof SelectEventCardByExpertAction) {
            return "Select event card";
        } else if (action instanceof CheckCardLimitAction) {
            return "Check card limit";
        }
        return "Wrong action";
    }

    public static void printPlayerStats(Stats stats){
        Player player = stats.getCurrentPlayer();
        System.out.println("__________STATS_____________");
        System.out.println("Player: " + player.getName());
        System.out.println("action number: " + stats.getActionNumber());
        System.out.println("Role: " + player.getRole().toString());
        System.out.println("City: " + player.getCity().getName());
        System.out.println("Distribution: " + stats.getDistribution());
        System.out.println("Breakout: " + stats.getBreakout());
        System.out.print("Cures:");
        for (Cure cure : stats.getInventedCures()) {
            System.out.print(cure.getColor() + " ");
        }

        System.out.println();
        System.out.print("Cards:");
        for (Player playerIterator : stats.getPlayers()) {
            System.out.print(playerIterator.getName() + "[" + playerIterator.getCity().getName() + "]:");
            for (Card card : playerIterator.getCards()) {
                System.out.print(card.getName());
                if (card instanceof CityCard) {
                    System.out.print("[" + ((CityCard) card).getCity().getColor() + "]");
                }
                System.out.print(",");
            }
            System.out.println();
        }
        System.out.println();
        List<City> labCities = stats.getLabCities();
        System.out.print("Cities with labs:");
        for (City city : labCities) {
            System.out.print(city.getName() + "[" + city.getColor() + "]" + ", ");
        }
        System.out.println();
        List<City> infectedCities = stats.getInfectedCities();
        System.out.println();
        System.out.print("Infected:");
        for (City city : infectedCities) {
            System.out.print(city.getName() + "(" + UiUtils.cityInfectionLabel(city) + "),");
        }
        System.out.println();
    }


    public static String cityInfectionLabel(City city) {
        String result = "";
        result += "bk:" + city.getDiseaseCountByColor(Disease.BLACK) + ";";
        result += "r:" + city.getDiseaseCountByColor(Disease.RED) + ";";
        result += "bl:" + city.getDiseaseCountByColor(Disease.BLUE) + ";";
        result += "y:" + city.getDiseaseCountByColor(Disease.YELLOW) + ";";
        return result;
    }

    public static void printDiseaseStats(List<Disease> diseases){
        System.out.println("Available diseases:");
        int i = 0;
        for (Disease disease : diseases) {
            System.out.println(i + ". " + disease.getColor());
            i += 1;
        }
    }

}
